package com.hjm.ui.comment.entity;

import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;

import java.util.Arrays;

public class Comment implements Parcelable {
    Integer id;
    int[] level;
    String text;
    int[] img;
    Integer goodsId;
    Integer storeId;
    Integer userId; // 评论的用户id
    Integer orderId;    // 属于商品评论时，orderId应不为空

    Integer userPic;    //用户头像
    String userName;    //用户名称
    String goodsType;   //款式

    Bitmap userPicBitmap;

    public Comment() {
    }

    protected Comment(Parcel in) {
        if (in.readByte() == 0) {
            id = null;
        } else {
            id = in.readInt();
        }
        level = in.createIntArray();
        text = in.readString();
        img = in.createIntArray();
        if (in.readByte() == 0) {
            goodsId = null;
        } else {
            goodsId = in.readInt();
        }
        if (in.readByte() == 0) {
            storeId = null;
        } else {
            storeId = in.readInt();
        }
        if (in.readByte() == 0) {
            userId = null;
        } else {
            userId = in.readInt();
        }
        if (in.readByte() == 0) {
            orderId = null;
        } else {
            orderId = in.readInt();
        }
        if (in.readByte() == 0) {
            userPic = null;
        } else {
            userPic = in.readInt();
        }
        userName = in.readString();
        goodsType = in.readString();
        userPicBitmap = in.readParcelable(Bitmap.class.getClassLoader());
    }

    public static final Creator<Comment> CREATOR = new Creator<Comment>() {
        @Override
        public Comment createFromParcel(Parcel in) {
            return new Comment(in);
        }

        @Override
        public Comment[] newArray(int size) {
            return new Comment[size];
        }
    };

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public int[] getLevel() {
        return level;
    }

    public void setLevel(int[] level) {
        this.level = level;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public int[] getImg() {
        return img;
    }

    public void setImg(int[] img) {
        this.img = img;
    }

    public Integer getGoodsId() {
        return goodsId;
    }

    public void setGoodsId(Integer goodsId) {
        this.goodsId = goodsId;
    }

    public Integer getStoreId() {
        return storeId;
    }

    public void setStoreId(Integer storeId) {
        this.storeId = storeId;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public Integer getOrderId() {
        return orderId;
    }

    public void setOrderId(Integer orderId) {
        this.orderId = orderId;
    }

    public Integer getUserPic() {
        return userPic;
    }

    public void setUserPic(Integer userPic) {
        this.userPic = userPic;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getGoodsType() {
        return goodsType;
    }

    public void setGoodsType(String goodsType) {
        this.goodsType = goodsType;
    }

    public Bitmap getUserPicBitmap() {
        return userPicBitmap;
    }

    public void setUserPicBitmap(Bitmap userPicBitmap) {
        this.userPicBitmap = userPicBitmap;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {

        if (id == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(id);
        }
        dest.writeIntArray(level);
        dest.writeString(text);
        dest.writeIntArray(img);
        if (goodsId == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(goodsId);
        }
        if (storeId == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(storeId);
        }
        if (userId == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(userId);
        }
        if (orderId == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(orderId);
        }
        if (userPic == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(userPic);
        }
        dest.writeString(userName);
        dest.writeString(goodsType);
        dest.writeParcelable(userPicBitmap, flags);
    }

    @Override
    public String toString() {
        return "Comment{" +
                "id=" + id +
                ", level=" + Arrays.toString(level) +
                ", text='" + text + '\'' +
                ", img=" + Arrays.toString(img) +
                ", goodsId=" + goodsId +
                ", storeId=" + storeId +
                ", userId=" + userId +
                ", orderId=" + orderId +
                ", userPic=" + userPic +
                ", userName='" + userName + '\'' +
                ", goodsType='" + goodsType + '\'' +
                ", userPicBitmap=" + userPicBitmap +
                '}';
    }
}
